﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MySQL.Db;

namespace Gollie.DataTables
{
	public class VendorUsersItem
	{
		public uint UserId { get; set; }
		public string UserName { get; set; }
		public uint RoleId { get; set; }
		public string RoleName { get; set; }
		public string LastName { get; set; }
		public string Initials { get; set; }
		public string Infix { get; set; }
		public DateTime LastLoginDate { get; set; }
	}

	public class VendorUsers : BaseBindable<VendorUsersItem>
	{
		public VendorUsers(uint vendorId)
		{
			ResultSet resultSet = Database.Queries.GetVendorUsers(vendorId);

			this.AddDetails(resultSet);
		}

		private void AddDetails(ResultSet resultSet)
		{
			int numRows = resultSet.Count;

			for (int i = 0; i < numRows; i++)
			{
				uint roleId = resultSet.GetUInt32(i, "roleid");

				this.Add(new VendorUsersItem()
				{
					UserId = resultSet.GetUInt32(i, "id"),
					UserName = resultSet.GetString(i, "username"),
					RoleId = roleId,
					RoleName = Enum.GetName(typeof(Role), roleId),
					LastName = resultSet.GetString(i, "lastname"),
					Initials = resultSet.GetString(i, "initials"),
					Infix = resultSet.GetString(i, "infix"),
					LastLoginDate = resultSet.GetDateTime(i, "lastlogindate")
				});
			}
		}
	}
}